package com.deng.springboot.demo.web.service.imp;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deng.springboot.demo.web.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * @author 邓力宾
 * @date 2020/3/1022:38
 * @Description:
 */
public class BaseServiceImpl<T, M extends BaseMapper<T>> implements IBaseService<T> {

    protected M mapper;

    @Autowired(required = true)
    public void setMapper(M mapper){
        this.mapper = mapper;
    }
    @Override
    public T getById(Serializable id) {
        return this.mapper.selectById(id);
    }

    @Override
    public int insert(T t) {
        return this.mapper.insert(t);
    }

    @Override
    public void deleteById(int id) {
        this.mapper.deleteById(id);
    }

    @Override
    public void logicRemove(int id) {

    }

    @Transactional(readOnly = true)
    @Override
    public IPage<T> getPage(int pageNum, int pageSize) {
        IPage<T> page = new Page<>(pageNum, pageSize);
        return this.mapper.selectPage(page, null);
    }
}
